source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-283.rds.xz")
summary(model)
SOM of size 10x10 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.348.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
442 635 805 928 1623 1022 705 363 263 496 180 722 844 833 667 1775
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
1271 798 968 758 302 658 524 998 658 1491 1666 1575 1069 448 293 600
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
824 1425 1119 785 883 1707 1776 1473 972 571 1850 1235 988 252 484 1490
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
1675 1089 1395 1020 434 1158 1394 1289 974 1006 732 1240 1883 1777 379 1580
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
1868 1093 1117 780 902 518 1564 1648 2487 412 1348 1013 753 742 686 745
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
354 1002 1344 372 1400 872 714 506 264 175 1188 238 172 466 1574 1619
97 98 99 100
899 456 314 37
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 10*10;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt precip longitud latitud altitud
[1,] 0.4537281 0.10406448 0.5800066 0.3104531 0.4304931
[2,] 0.6136018 -0.06943821 -0.3970454 -0.1187163 -0.3779586
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud latitud altitud fecha_cnt precip
0.9798727 0.9719220 0.9695892 0.9519645 0.9439548
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 34.00 Min. :0
1st Qu.: 3.000 1st Qu.:131.0 1st Qu.: 60.00 1st Qu.: 49.00 1st Qu.:0
Median : 9.000 Median :157.0 Median : 82.00 Median : 59.00 Median :0
Mean : 7.381 Mean :163.2 Mean : 85.92 Mean : 67.26 Mean :0
3rd Qu.:11.000 3rd Qu.:191.5 3rd Qu.:110.00 3rd Qu.: 76.00 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.79 1st Qu.: -6.350 1st Qu.: 32.0
Median : 0.0000 Median :42.34 Median : -3.819 Median : 98.0
Mean : 0.2192 Mean :41.48 Mean : -3.628 Mean : 214.5
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.636 3rd Qu.: 336.0
Max. :607.0000 Max. :43.57 Max. : 4.216 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:149.0 1st Qu.: 49.00 1st Qu.: 3.00
Median : 6.000 Median :198.0 Median : 95.00 Median : 10.00
Mean : 6.429 Mean :201.6 Mean : 95.49 Mean : 13.17
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.: 144.00 3rd Qu.: 20.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :135.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.95 1st Qu.: -4.8458
Median :0.000000 Median : 0.0000 Median :40.95 Median : -2.4831
Mean :0.000342 Mean : 0.5223 Mean :40.48 Mean : -2.3604
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.5356
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 263.0
Mean : 425.6
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.505 Mean :217.4 Mean :150.6 Mean : 6.999 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03084 Mean :28.37 Mean :-16.05 Mean : 518.3
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 34.00 Min. :0
1st Qu.: 3.000 1st Qu.:131.0 1st Qu.: 60.00 1st Qu.: 49.00 1st Qu.:0
Median : 9.000 Median :157.0 Median : 82.00 Median : 59.00 Median :0
Mean : 7.381 Mean :163.2 Mean : 85.92 Mean : 67.26 Mean :0
3rd Qu.:11.000 3rd Qu.:191.5 3rd Qu.:110.00 3rd Qu.: 76.00 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.79 1st Qu.: -6.350 1st Qu.: 32.0
Median : 0.0000 Median :42.34 Median : -3.819 Median : 98.0
Mean : 0.2192 Mean :41.48 Mean : -3.628 Mean : 214.5
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.636 3rd Qu.: 336.0
Max. :607.0000 Max. :43.57 Max. : 4.216 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:152.0 1st Qu.: 52.00 1st Qu.: 3.00
Median : 6.000 Median :201.0 Median : 97.00 Median : 9.00
Mean : 6.427 Mean :205.5 Mean : 98.23 Mean :12.45
3rd Qu.: 9.000 3rd Qu.:262.0 3rd Qu.: 145.00 3rd Qu.:19.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :87.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-4.8500
Median :0.000000 Median : 0.00000 Median :40.93 Median :-2.4831
Mean :0.000354 Mean : 0.04781 Mean :40.43 Mean :-2.4232
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 0.4914
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.0
Mean : 368.4
3rd Qu.: 656.0
Max. :1971.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 17.00
Median : 6.00 Median : 73.00 Median : 6.00 Median : 30.00
Mean : 6.51 Mean : 82.95 Mean : 12.65 Mean : 34.91
3rd Qu.:10.00 3rd Qu.:133.00 3rd Qu.: 58.00 3rd Qu.: 48.00
Max. :12.00 Max. :263.00 Max. : 148.00 Max. :135.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 14.85 Mean :41.91 Mean : -0.4648
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.3656
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2228
Mean :2152
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.505 Mean :217.4 Mean :150.6 Mean : 6.999 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03084 Mean :28.37 Mean :-16.05 Mean : 518.3
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 50.0 Min. :-30.00 Min. : 34.00 Min. :0
1st Qu.: 3.000 1st Qu.:133.0 1st Qu.: 60.00 1st Qu.: 48.00 1st Qu.:0
Median : 9.000 Median :159.0 Median : 83.00 Median : 58.00 Median :0
Mean : 7.442 Mean :164.9 Mean : 86.71 Mean : 61.92 Mean :0
3rd Qu.:11.000 3rd Qu.:193.0 3rd Qu.:111.00 3rd Qu.: 72.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :125.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.71 1st Qu.: -6.056 1st Qu.: 32.0
Median : 0.00000 Median :42.33 Median : -3.799 Median : 95.0
Mean : 0.06001 Mean :41.48 Mean : -3.428 Mean : 205.2
3rd Qu.: 0.00000 3rd Qu.:43.31 3rd Qu.: -1.033 3rd Qu.: 334.5
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:152.0 1st Qu.: 52.00 1st Qu.: 3.00
Median : 6.000 Median :201.0 Median : 97.00 Median : 9.00
Mean : 6.427 Mean :205.5 Mean : 98.23 Mean :12.45
3rd Qu.: 9.000 3rd Qu.:262.0 3rd Qu.: 145.00 3rd Qu.:19.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :87.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-4.8500
Median :0.000000 Median : 0.00000 Median :40.93 Median :-2.4831
Mean :0.000354 Mean : 0.04781 Mean :40.43 Mean :-2.4232
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 0.4914
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.0
Mean : 368.4
3rd Qu.: 656.0
Max. :1971.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 17.00
Median : 6.00 Median : 73.00 Median : 6.00 Median : 30.00
Mean : 6.51 Mean : 82.95 Mean : 12.65 Mean : 34.91
3rd Qu.:10.00 3rd Qu.:133.00 3rd Qu.: 58.00 3rd Qu.: 48.00
Max. :12.00 Max. :263.00 Max. : 148.00 Max. :135.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 14.85 Mean :41.91 Mean : -0.4648
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.3656
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2228
Mean :2152
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :104.0 Min. :0
1st Qu.: 2.000 1st Qu.:116.8 1st Qu.: 51.00 1st Qu.:122.8 1st Qu.:0
Median : 6.000 Median :133.0 Median : 72.00 Median :135.5 Median :0
Mean : 6.477 Mean :139.3 Mean : 74.29 Mean :146.2 Mean :0
3rd Qu.:11.000 3rd Qu.:158.2 3rd Qu.: 95.00 3rd Qu.:154.2 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.89 1st Qu.: -8.624 1st Qu.: 58.0
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 2.574 Mean :41.48 Mean : -6.594 Mean : 352.7
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.000 Max. :43.57 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.505 Mean :217.4 Mean :150.6 Mean : 6.999 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03084 Mean :28.37 Mean :-16.05 Mean : 518.3
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 50.0 Min. :-30.00 Min. : 34.00 Min. :0
1st Qu.: 3.000 1st Qu.:133.0 1st Qu.: 60.00 1st Qu.: 48.00 1st Qu.:0
Median : 9.000 Median :159.0 Median : 83.00 Median : 58.00 Median :0
Mean : 7.442 Mean :164.9 Mean : 86.71 Mean : 61.92 Mean :0
3rd Qu.:11.000 3rd Qu.:193.0 3rd Qu.:111.00 3rd Qu.: 72.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :125.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.71 1st Qu.: -6.056 1st Qu.: 32.0
Median : 0.00000 Median :42.33 Median : -3.799 Median : 95.0
Mean : 0.06001 Mean :41.48 Mean : -3.428 Mean : 205.2
3rd Qu.: 0.00000 3rd Qu.:43.31 3rd Qu.: -1.033 3rd Qu.: 334.5
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:128.0 1st Qu.: 28.00 1st Qu.: 5.00
Median :3.000 Median :161.0 Median : 61.00 Median :14.00
Mean :2.865 Mean :161.5 Mean : 60.56 Mean :15.92
3rd Qu.:4.000 3rd Qu.:191.0 3rd Qu.: 91.00 3rd Qu.:24.00
Max. :9.000 Max. :355.0 Max. :236.00 Max. :87.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.649
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-5.289
Median :0.000000 Median : 0.00000 Median :40.95 Median :-2.331
Mean :0.000662 Mean : 0.09857 Mean :40.50 Mean :-2.308
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 0.595
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 192.0
Mean : 355.1
3rd Qu.: 628.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 17.00
Median : 6.00 Median : 73.00 Median : 6.00 Median : 30.00
Mean : 6.51 Mean : 82.95 Mean : 12.65 Mean : 34.91
3rd Qu.:10.00 3rd Qu.:133.00 3rd Qu.: 58.00 3rd Qu.: 48.00
Max. :12.00 Max. :263.00 Max. : 148.00 Max. :135.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 14.85 Mean :41.91 Mean : -0.4648
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.3656
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2228
Mean :2152
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :104.0 Min. :0
1st Qu.: 2.000 1st Qu.:116.8 1st Qu.: 51.00 1st Qu.:122.8 1st Qu.:0
Median : 6.000 Median :133.0 Median : 72.00 Median :135.5 Median :0
Mean : 6.477 Mean :139.3 Mean : 74.29 Mean :146.2 Mean :0
3rd Qu.:11.000 3rd Qu.:158.2 3rd Qu.: 95.00 3rd Qu.:154.2 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.89 1st Qu.: -8.624 1st Qu.: 58.0
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 2.574 Mean :41.48 Mean : -6.594 Mean : 352.7
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.000 Max. :43.57 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 4.00 Min. : 8.0 Min. :-110.0 Min. : 0.00
1st Qu.: 7.00 1st Qu.:182.0 1st Qu.: 79.0 1st Qu.: 2.00
Median : 8.00 Median :237.0 Median : 126.0 Median : 8.00
Mean : 8.45 Mean :230.5 Mean : 119.6 Mean :10.47
3rd Qu.:10.00 3rd Qu.:284.0 3rd Qu.: 164.0 3rd Qu.:16.00
Max. :12.00 Max. :403.0 Max. : 254.0 Max. :52.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-4.8500
Median :0.0000000 Median : 0.00000 Median :40.87 Median :-2.7331
Mean :0.0001782 Mean : 0.01897 Mean :40.39 Mean :-2.4887
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.96 3rd Qu.: 0.4731
Max. :3.0000000 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 259.5
Mean : 376.0
3rd Qu.: 667.0
Max. :1971.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.505 Mean :217.4 Mean :150.6 Mean : 6.999 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03084 Mean :28.37 Mean :-16.05 Mean : 518.3
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 50.0 Min. :-30.00 Min. : 34.00 Min. :0
1st Qu.: 3.000 1st Qu.:133.0 1st Qu.: 60.00 1st Qu.: 48.00 1st Qu.:0
Median : 9.000 Median :159.0 Median : 83.00 Median : 58.00 Median :0
Mean : 7.442 Mean :164.9 Mean : 86.71 Mean : 61.92 Mean :0
3rd Qu.:11.000 3rd Qu.:193.0 3rd Qu.:111.00 3rd Qu.: 72.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :125.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.71 1st Qu.: -6.056 1st Qu.: 32.0
Median : 0.00000 Median :42.33 Median : -3.799 Median : 95.0
Mean : 0.06001 Mean :41.48 Mean : -3.428 Mean : 205.2
3rd Qu.: 0.00000 3rd Qu.:43.31 3rd Qu.: -1.033 3rd Qu.: 334.5
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:128.0 1st Qu.: 28.00 1st Qu.: 5.00
Median :3.000 Median :161.0 Median : 61.00 Median :14.00
Mean :2.865 Mean :161.5 Mean : 60.56 Mean :15.92
3rd Qu.:4.000 3rd Qu.:191.0 3rd Qu.: 91.00 3rd Qu.:24.00
Max. :9.000 Max. :355.0 Max. :236.00 Max. :87.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.649
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-5.289
Median :0.000000 Median : 0.00000 Median :40.95 Median :-2.331
Mean :0.000662 Mean : 0.09857 Mean :40.50 Mean :-2.308
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 0.595
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 192.0
Mean : 355.1
3rd Qu.: 628.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 17.00
Median : 6.00 Median : 73.00 Median : 6.00 Median : 30.00
Mean : 6.51 Mean : 82.95 Mean : 12.65 Mean : 34.91
3rd Qu.:10.00 3rd Qu.:133.00 3rd Qu.: 58.00 3rd Qu.: 48.00
Max. :12.00 Max. :263.00 Max. : 148.00 Max. :135.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 14.85 Mean :41.91 Mean : -0.4648
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.3656
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2228
Mean :2152
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :104.0 Min. :0
1st Qu.: 2.000 1st Qu.:117.0 1st Qu.: 50.50 1st Qu.:122.0 1st Qu.:0
Median : 6.000 Median :134.0 Median : 72.00 Median :133.0 Median :0
Mean : 6.527 Mean :137.6 Mean : 72.93 Mean :136.2 Mean :0
3rd Qu.:11.000 3rd Qu.:158.5 3rd Qu.: 95.00 3rd Qu.:147.0 3rd Qu.:0
Max. :12.000 Max. :326.0 Max. :207.00 Max. :197.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.98 1st Qu.: -8.624 1st Qu.: 43.3
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 2.842 Mean :41.54 Mean : -6.546 Mean : 341.7
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.000 Max. :43.57 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-50.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:193.0 1st Qu.:100.0 1st Qu.: 2.00
Median : 8.000 Median :241.0 Median :142.0 Median : 7.00
Mean : 8.543 Mean :236.7 Mean :135.2 Mean :10.97
3rd Qu.:10.000 3rd Qu.:284.0 3rd Qu.:175.0 3rd Qu.:17.00
Max. :12.000 Max. :403.0 Max. :254.0 Max. :52.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:37.96 1st Qu.:-5.5975
Median :0.0000000 Median : 0.00000 Median :41.17 Median :-1.2294
Mean :0.0001858 Mean : 0.01425 Mean :40.28 Mean :-1.9815
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.33 3rd Qu.: 0.7106
Max. :3.0000000 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 22.0
Median : 71.0
Mean :148.4
3rd Qu.:247.0
Max. :953.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-110.00 Min. : 0.000
1st Qu.: 6.000 1st Qu.:156.0 1st Qu.: 48.00 1st Qu.: 2.000
Median : 8.000 Median :226.5 Median : 95.00 Median : 8.000
Mean : 8.285 Mean :219.4 Mean : 91.94 Mean : 9.599
3rd Qu.:10.000 3rd Qu.:284.0 3rd Qu.: 135.00 3rd Qu.:14.000
Max. :12.000 Max. :400.0 Max. : 250.00 Max. :48.000
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :37.13 Min. :-8.411
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.:-4.680
Median :0.0000000 Median : 0.00000 Median :40.66 Median :-3.764
Mean :0.0001647 Mean : 0.02734 Mean :40.59 Mean :-3.388
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.52 3rd Qu.:-2.138
Max. :2.0000000 Max. :35.00000 Max. :43.12 Max. : 2.438
altitud
Min. : 370.0
1st Qu.: 627.0
Median : 735.0
Mean : 779.3
3rd Qu.: 916.0
Max. :1971.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.505 Mean :217.4 Mean :150.6 Mean : 6.999 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03084 Mean :28.37 Mean :-16.05 Mean : 518.3
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1 Min. : 37.0 Min. :-11.00 Min. :191.0 Min. :0
1st Qu.: 2 1st Qu.:115.0 1st Qu.: 63.00 1st Qu.:209.0 1st Qu.:0
Median : 4 Median :125.0 Median : 75.00 Median :227.0 Median :0
Mean : 6 Mean :154.7 Mean : 87.27 Mean :242.8 Mean :0
3rd Qu.:10 3rd Qu.:156.0 3rd Qu.: 92.00 3rd Qu.:252.0 3rd Qu.:0
Max. :12 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.:0 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 261.0
Median :0 Median :42.24 Median : -8.411 Median : 263.0
Mean :0 Mean :40.94 Mean : -7.051 Mean : 459.1
3rd Qu.:0 3rd Qu.:42.89 3rd Qu.: -3.174 3rd Qu.: 370.0
Max. :0 Max. :43.36 Max. : 2.825 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. :1.00 Min. : 50.0 Min. :-22.00 Min. : 34.00 Min. :0
1st Qu.:2.00 1st Qu.:127.0 1st Qu.: 54.00 1st Qu.: 47.00 1st Qu.:0
Median :3.00 Median :150.0 Median : 72.00 Median : 57.00 Median :0
Mean :2.93 Mean :154.2 Mean : 74.01 Mean : 60.06 Mean :0
3rd Qu.:4.00 3rd Qu.:176.0 3rd Qu.: 93.00 3rd Qu.: 70.00 3rd Qu.:0
Max. :7.00 Max. :301.0 Max. :186.00 Max. :115.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.6494 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:41.29 1st Qu.:-5.6156 1st Qu.: 29.0
Median : 0.00000 Median :42.44 Median :-2.6544 Median : 90.0
Mean : 0.06496 Mean :41.77 Mean :-2.6710 Mean : 157.5
3rd Qu.: 0.00000 3rd Qu.:43.31 3rd Qu.: 0.4914 3rd Qu.: 251.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :1055.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:128.0 1st Qu.: 28.00 1st Qu.: 5.00
Median :3.000 Median :161.0 Median : 61.00 Median :14.00
Mean :2.865 Mean :161.5 Mean : 60.56 Mean :15.92
3rd Qu.:4.000 3rd Qu.:191.0 3rd Qu.: 91.00 3rd Qu.:24.00
Max. :9.000 Max. :355.0 Max. :236.00 Max. :87.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.649
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-5.289
Median :0.000000 Median : 0.00000 Median :40.95 Median :-2.331
Mean :0.000662 Mean : 0.09857 Mean :40.50 Mean :-2.308
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 0.595
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 192.0
Mean : 355.1
3rd Qu.: 628.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 17.00
Median : 6.00 Median : 73.00 Median : 6.00 Median : 30.00
Mean : 6.51 Mean : 82.95 Mean : 12.65 Mean : 34.91
3rd Qu.:10.00 3rd Qu.:133.00 3rd Qu.: 58.00 3rd Qu.: 48.00
Max. :12.00 Max. :263.00 Max. : 148.00 Max. :135.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.38 Median : 0.8842
Mean :0 Mean : 14.85 Mean :41.91 Mean : -0.4648
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.3656
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1167
1st Qu.:1894
Median :2228
Mean :2152
3rd Qu.:2316
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :104.0 Min. :0
1st Qu.: 2.000 1st Qu.:117.0 1st Qu.: 50.50 1st Qu.:122.0 1st Qu.:0
Median : 6.000 Median :134.0 Median : 72.00 Median :133.0 Median :0
Mean : 6.527 Mean :137.6 Mean : 72.93 Mean :136.2 Mean :0
3rd Qu.:11.000 3rd Qu.:158.5 3rd Qu.: 95.00 3rd Qu.:147.0 3rd Qu.:0
Max. :12.000 Max. :326.0 Max. :207.00 Max. :197.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.98 1st Qu.: -8.624 1st Qu.: 43.3
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 2.842 Mean :41.54 Mean : -6.546 Mean : 341.7
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.000 Max. :43.57 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-50.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:193.0 1st Qu.:100.0 1st Qu.: 2.00
Median : 8.000 Median :241.0 Median :142.0 Median : 7.00
Mean : 8.543 Mean :236.7 Mean :135.2 Mean :10.97
3rd Qu.:10.000 3rd Qu.:284.0 3rd Qu.:175.0 3rd Qu.:17.00
Max. :12.000 Max. :403.0 Max. :254.0 Max. :52.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:37.96 1st Qu.:-5.5975
Median :0.0000000 Median : 0.00000 Median :41.17 Median :-1.2294
Mean :0.0001858 Mean : 0.01425 Mean :40.28 Mean :-1.9815
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.33 3rd Qu.: 0.7106
Max. :3.0000000 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 22.0
Median : 71.0
Mean :148.4
3rd Qu.:247.0
Max. :953.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-110.00 Min. : 0.000
1st Qu.: 6.000 1st Qu.:156.0 1st Qu.: 48.00 1st Qu.: 2.000
Median : 8.000 Median :226.5 Median : 95.00 Median : 8.000
Mean : 8.285 Mean :219.4 Mean : 91.94 Mean : 9.599
3rd Qu.:10.000 3rd Qu.:284.0 3rd Qu.: 135.00 3rd Qu.:14.000
Max. :12.000 Max. :400.0 Max. : 250.00 Max. :48.000
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :37.13 Min. :-8.411
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.:-4.680
Median :0.0000000 Median : 0.00000 Median :40.66 Median :-3.764
Mean :0.0001647 Mean : 0.02734 Mean :40.59 Mean :-3.388
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.52 3rd Qu.:-2.138
Max. :2.0000000 Max. :35.00000 Max. :43.12 Max. : 2.438
altitud
Min. : 370.0
1st Qu.: 627.0
Median : 735.0
Mean : 779.3
3rd Qu.: 916.0
Max. :1971.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.488 Mean :233.9 Mean :169.4 Mean : 6.329 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :103.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003517 Mean :28.38 Mean :-15.96 Mean :131.3
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 6.00 Min. : 53.0 Min. :-30.00 Min. : 34.00 Min. :0
1st Qu.:10.00 1st Qu.:137.2 1st Qu.: 67.00 1st Qu.: 49.00 1st Qu.:0
Median :11.00 Median :170.0 Median : 94.00 Median : 58.00 Median :0
Mean :10.67 Mean :172.5 Mean : 95.78 Mean : 63.25 Mean :0
3rd Qu.:12.00 3rd Qu.:205.0 3rd Qu.:124.00 3rd Qu.: 74.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.00 Max. :125.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.95 1st Qu.: -6.829 1st Qu.: 34.0
Median : 0.00000 Median :42.33 Median : -3.831 Median : 108.0
Mean : 0.05647 Mean :41.27 Mean : -3.969 Mean : 239.2
3rd Qu.: 0.00000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 370.0
Max. :27.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 51.00 Median : 3.00 Median :0
Mean : 6.582 Mean :138.4 Mean : 60.86 Mean : 10.21 Mean :0
3rd Qu.: 9.250 3rd Qu.:183.0 3rd Qu.: 98.25 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :114.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1768 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1 Min. : 37.0 Min. :-11.00 Min. :191.0 Min. :0
1st Qu.: 2 1st Qu.:115.0 1st Qu.: 63.00 1st Qu.:209.0 1st Qu.:0
Median : 4 Median :125.0 Median : 75.00 Median :227.0 Median :0
Mean : 6 Mean :154.7 Mean : 87.27 Mean :242.8 Mean :0
3rd Qu.:10 3rd Qu.:156.0 3rd Qu.: 92.00 3rd Qu.:252.0 3rd Qu.:0
Max. :12 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.:0 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 261.0
Median :0 Median :42.24 Median : -8.411 Median : 263.0
Mean :0 Mean :40.94 Mean : -7.051 Mean : 459.1
3rd Qu.:0 3rd Qu.:42.89 3rd Qu.: -3.174 3rd Qu.: 370.0
Max. :0 Max. :43.36 Max. : 2.825 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)